package com.aaa.hospital.service.impl;

import com.aaa.hospital.mapper.DeptMapper;
import com.aaa.hospital.pojo.domain.Dept;
import com.aaa.hospital.pojo.query.DeptQuery;
import com.aaa.hospital.result.AjaxResult;
import com.aaa.hospital.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;

/**
 * @Author: HJT
 * @DateTime: 2022/1/15 12:53
 * @Description: TODO
 */
@Service
public class DeptServiceImpl implements DeptService {
    @Autowired
    private DeptMapper deptMapper;
    @Override
    public AjaxResult queryDept(DeptQuery query) {
        List<Dept> depts = deptMapper.queryDept(query);
        Long aLong = deptMapper.queryDeptTotal(query);
        HashMap<Object, Object> objectObjectHashMap = new HashMap<>();
        objectObjectHashMap.put("currentData",depts);
        objectObjectHashMap.put("totalCount",aLong);
        return AjaxResult.success(objectObjectHashMap);
    }

    @Override
    public AjaxResult addDept(Dept dept) {
       int i =  deptMapper.addDept(dept);
        if (i>0){
            return AjaxResult.success();
        }
        return AjaxResult.fail();
    }

    @Override
    public AjaxResult deleteDept(Integer id) {
        int i = deptMapper.deleteDept(id);
        if (i>0){
            return AjaxResult.success();
        }
        return AjaxResult.fail();
    }

    @Override
    public AjaxResult getDept(Integer id) {
        Dept d = deptMapper.getDept(id);
        return AjaxResult.success(d);
    }

    @Override
    public AjaxResult updateDept(Dept dept) {
        int i =  deptMapper.updateDept(dept);
        if (i>0){
            return AjaxResult.success();
        }
        return AjaxResult.fail();
    }

    @Override
    public AjaxResult list() {
        List<Dept> depts = deptMapper.listDept();
        return AjaxResult.success(depts);
    }
}
